import { request } from '@/app/http'
import { toRangeParam } from 'app/converter'

const PATH = '/menus'

export async function getMyMenus() {
  const { data } = await request({
    url: PATH + '/build',
    method: 'get'
  })
  return data
}

export async function menuTree() {
  const { data } = await request({
    url: PATH + '/menuTree',
    method: 'get'
  })
  return data
}

export async function searchMenu(params) {
  return request({
    url: PATH,
    method: 'get',
    params: { ...toRangeParam(params) }
  })
}

export function addMenu(data) {
  return request({
    url: PATH,
    method: 'post',
    data
  })
}

export function updateMenu(data) {
  return request({
    url: PATH,
    method: 'put',
    data
  })
}

export function removeMenu(data) {
  return request({
    url: PATH,
    method: 'delete',
    data,
    showLoading: true,
    showMsg: true
  })
}

export function downloadMenu(params) {
  return request({
    url: PATH + '/download',
    method: 'get',
    params,
    responseType: 'blob',
    showLoading: true,
    showMsg: true
  })
}
